﻿<%@ Page Language="C#" MasterPageFile="~/Layouts/List.Master" AutoEventWireup="true"
    CodeBehind="OrganizationList.aspx.cs" Inherits="Bingosoft.WebApp.Modules.SecurityConsole.Organization.OrganizationList" %>

<asp:Content ContentPlaceHolderID="head" ID="idFormTitle" runat="server">
    <!-- title -->
</asp:Content>
<asp:Content ID="idContent" ContentPlaceHolderID="Content" runat="Server">
    <!-- 搜索框 -->
    <div class="search" style="margin-top: 2px;">
        <web:search ID="GridSearch" GridViewId="SmartGridView1" runat="server">
            <SearchConditionTemplate>
                <table cellpadding="0" cellspacing="0" width="95%">
                    <tr>
                        <th>
                            组织名称：
                        </th>
                        <td>
                            <asp:TextBox ID="Name" name="Name" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </SearchConditionTemplate>
        </web:search>
    </div>
    <div class="datalist">
        <!-- 标题头 -->
        <h2 style="height: 30px;">
            组织信息列表
        </h2>
        <!-- 工具栏 -->
        <div class="toolbar" style="height: 30px;" id="divToolbar" runat="server">
            <asp:LinkButton runat="server" OnClientClick="return openEditor(this, 'Insert');"
                OnClick="RefreshGrid" _visible="ORGANIZATION_MANAGE$CREATE">
                <span>
                    <img alt="" runat="server" id="img1" src="~/Images/icon_new.gif" style="border: 0px" />新建
                </span>
            </asp:LinkButton>
        </div>
        <div class="datagrid" style="clear: left;">
            <!--------------------------- List Area --------------------------->
            <web:SmartGridView ID="SmartGridView1" runat="server" AutoGenerateColumns="False"
                Width="100%" DataKeyNames="Id" DataSourceID="SmartDataSource1" OnRowDataBound="SmartGridView1_RowDataBound"
                AllowPaging="True" AllowSorting="True" EnableModelValidation="True">
                <FixRowColumnSettings MarginLeft="" MarginRight=""></FixRowColumnSettings>
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="组织名称" SortExpression="Name" />
                    <asp:BoundField DataField="ParentName" HeaderText="上级组织名称" SortExpression="ParentName" />
                    <asp:TemplateField HeaderText="状态" SortExpression="Status">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Status").ToString()=="enabled"?"已启用":"已停用" %>'></asp:Label>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="操作">
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle Wrap="False" HorizontalAlign="Center" />
                        <ItemTemplate>
                            <table width="46px">
                                <tr>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ibtnEdit" runat="server" ToolTip="修改" _KeyId='<%#Eval("Id")%>'
                                            _visible="ORGANIZATION_MANAGE$EDIT" ImageUrl="~/images/com/dg_edit.gif" CausesValidation="False"
                                            OnClientClick="return openEditor(this, 'Edit');" OnClick="RefreshGrid"></asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;" runat="server" id="tdDelete" _ParentId='<%#Eval("Parent")%>'>
                                        <asp:ImageButton ID="ibtnDelete" runat="server" ToolTip="删除" ImageUrl="~/images/com/dg_del.gif"
                                            _KeyId='<%#Eval("Id")%>' _visible="ORGANIZATION_MANAGE$DELETE" OnClientClick="return confirm('您确认要删除吗?')"
                                            OnClick="DelOrg"></asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="分配管理角色" ImageUrl="~/Images/ico_assign_role.gif"
                                            _KeyId='<%#Eval("Id")%>' _visible="ORGANIZATION_MANAGE$ASSIGN_ROLE" CausesValidation="False" OnClientClick="return showRoleList(this,'Manage')">
                                        </asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ImageButton2" runat="server" ToolTip="分配流程角色" ImageUrl="~/Images/ico_entrust.gif"
                                            _KeyId='<%#Eval("Id")%>' _visible="ORGANIZATION_MANAGE$ASSIGN_WORKFLOW_ROLE" CausesValidation="False" OnClientClick="return showRoleList(this,'Process')">
                                        </asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="EnableImageButton" runat="server" ToolTip="启用" _KeyId='<%#Eval("Id")%>'
                                            _Status='<%#Eval("Status")%>' _visible="ORGANIZATION_MANAGE$ENABLE" ImageUrl="~/Images/ico_start.gif" CausesValidation="False"
                                            OnClick="EnableOrg"></asp:ImageButton>
                                        <asp:ImageButton ID="DisableImageButton" runat="server" ToolTip="停用" _KeyId='<%#Eval("Id")%>'
                                            ImageUrl="~/Images/ico_pause.gif" _visible="ORGANIZATION_MANAGE$DISABLE" CausesValidation="False" OnClick="DisableOrg" >
                                        </asp:ImageButton>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerSettings />
                <EditRowStyle HorizontalAlign="Center" />
            </web:SmartGridView>
            <web:SmartSqlDataSource ID="SmartDataSource1" runat="server" SelectCommand="organization.list"
                SelectCommandAutoPageWrap="true" DefaultSortExpression="Id desc">
            </web:SmartSqlDataSource>
        </div>
    </div>
    <script type="text/javascript">
        var parentId = "<%=parent %>";
        var parentName = "<%=parentName %>";

        function openEditor(_this, action) {
            var url = "OrganizationEdit.aspx";
            // FormViewMode : Insert/Edit/ReadOnly
            var params = { FormViewMode: action }
            if (action == "Insert") {
                params.title = "组织机构新增";
                params.Parent = parentId;
                params.ParentName = parentName;
                params.Random = Math.random();
            } else if (action == "Edit") {
                params.title = "组织机构编辑";
                params.Id = _this.attributes["_KeyId"].value;
                params.Random = Math.random();
            }
            var returnValue = showCenterModalDialog(buildUrl(url, params), 500, 180);
            window.parent.reloadTree();
            return true;
        }

        //分配管理角色&流程角色
        function showRoleList(link, type) {
            var url = "";
            var params = {};
            params.OrgId = link.attributes["_KeyId"].value;
            if (type == "Manage") {
                url = "OrganizationManageRoleList.aspx";
                params.title = "组织[管理角色]列表";
                params.Random = Math.random();
            }
            else {
                url = "OrganizationProcessRoleList.aspx";
                params.title = "组织[流程角色]列表";
                params.Random = Math.random();
            }
            var returnValue = showCenterModalDialog(buildUrl(url, params), 700, 450);
            return false;
        }
    </script>
</asp:Content>
